﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows;
using System.Windows.Forms;
using ReflectionStudio.Core.Events;
 using System.Data.OracleClient; 
using INTEX.DataBase;
namespace WPFExcelReport
{
   

    public class TrisType
    {
        public string TrisCode = "";
        public string TrisDirect = "";
        public string Description = "";
        public TrisType(string triscode, string trisdirect, string description)
        {
            TrisCode = triscode;
            TrisDirect = trisdirect;
            Description = description;
        }
    }
    public class GBInventory
    {
        public string INVDATE;
        public string ARTICLE;
        public string VAR;
        public string COLOR;
        public string SPPART;
        public string FBPART;
        public double LASTWEI;
        public GBInventory()
        {
        }
        public GBInventory(string invdate,string article,string color,string sppart,string fbpart,double lastwei,string var="  ")
        {
            INVDATE = invdate;
            ARTICLE = article;
            VAR = var;
            COLOR = color;
            SPPART = sppart;
            FBPART = fbpart;
            LASTWEI = lastwei;
        }

    }
    public class WBInventory
    {
        #region ----------SUN------------------
        public string ARTICLE;
        public string FINISH;
        public string MATSOURCE, MATLOT = ""; 
 
        public string WH;
        public string WBBWAKZ;
        public int STARTPCNUM = 0;
        public double STARTQTY;

        public int MOVINPCNUM = 0;
        public double MOVINQTY;
        public int MOVOUTPCNUM = 0;
        public double MOVOUTQTY;

        public int ENDPCNUM = 0;
        public double ENDQTY;
        #endregion
        public string Article;
        public string INVDATE;
        public string LASTINVDATE;
        public string WBBDPART;
        public int LastPcNum = 0;
        public double lastQtyMtr;
        public string WBBLO;
        public WBInventory()
        {
        }
        public WBInventory(string invdate, string wblo, string article, string wbbdpart, int lastpcnum, double lastqtymtr)
        {
            WBBLO = wblo;
            INVDATE = invdate;
            Article = article;
            LastPcNum = lastpcnum;
            lastQtyMtr = lastqtymtr;
            WBBDPART = wbbdpart;
        }
        public WBInventory(string invdate, string wblo, string wBBWAKZ,string article, string _FINISH, string wbbdpart, int lastpcnum, double lastqtymtr)
        {
            WH = wblo;
            INVDATE = invdate;
            WBBWAKZ = wBBWAKZ;
            ARTICLE = article;
            FINISH = _FINISH;
            WBBDPART = wbbdpart;
            ENDPCNUM = lastpcnum;
            ENDQTY = lastqtymtr;
            MATSOURCE = wbbdpart;
            STARTPCNUM = lastpcnum;
            STARTQTY = lastqtymtr;
        }
        //(lastInvDate, WBBLO, ARTICLE,FINISH, WBBDPART, INVPCNUM, INVQTYMTR);
        public WBInventory(string invdate, string wblo, string wBBWAKZ, string article, string wbbdpart, int lastpcnum, double lastqtymtr)
        {
            WH = wblo;
            INVDATE = invdate;
            WBBWAKZ = wBBWAKZ;
            ARTICLE = article;
            ENDPCNUM = lastpcnum;
            ENDQTY = lastqtymtr;
            MATSOURCE = wbbdpart;
            STARTPCNUM = lastpcnum;
            STARTQTY = lastqtymtr;
        }
    }
    public class GBMOVEMENT
    {
        public int ICCGLDAT;
        public string ARTICLE;
        public string ATRICLEDES;
        public string COLOR;
        public string COLORDES;
        public string SPPART;
        public string FBPART;
        public string TYPE;
        public string SUPPLIER;
        public string DES;
        public string ORDERNO;
        public double STARTWEI;
        public double INWEI;
        public double OUTWEI;
        public double ADJWEI;
        public double ENDWEI;
        public GBMOVEMENT()
        {
        }
        public GBMOVEMENT(int m_ICCGLDAT, string m_ARTICLE, string m_ARTICLEDES, string m_COLOR, string m_COLORDES, string _SPPART, string _FBPART,
            string _TYPE, string _SUPPLIER, string _DES, string _ORDERNO, double _STARTWEI, double _INWEI, double _OUTWEI, double _ADJWEI, double _ENDWEI)
        {
            ICCGLDAT = m_ICCGLDAT;
            ARTICLE = m_ARTICLE;
            ATRICLEDES = m_ARTICLEDES;
            COLOR = m_COLOR;
            COLORDES = m_COLORDES;
            SPPART = _SPPART;
            FBPART = _FBPART;
            TYPE = _TYPE;
            SUPPLIER = _SUPPLIER;
            DES = _DES;
            ORDERNO = _ORDERNO;
            STARTWEI = STARTWEI;
            INWEI = _INWEI;
            OUTWEI = _OUTWEI;
            ADJWEI = _ADJWEI;
            ENDWEI = _ENDWEI;
        }

    }
    public class WBMOVEMENT
    {
        public int ICCWBMDAT;
        public string ICCWBMTYPE;
        public string ICCWBMWAKZ;
        public string ICCWBMBS;
        public int ICCWBMBELEG;
        public string ARTICLE;
        public string ICCWBMBESCHICH;
        public string ICCWBMDPART;
        public string ICCWBMCODE;
        public string ICCWBMNAME;
        public string ICCWBMBDES;
        public string ICCWBMAUFTYP;
        public string ORDERNO;
        public double STARTMTR;
        public int STARTPCNUM;
        public double INMTR;
        public int INPCNUM;
        public double OUTMTR;
        public int OUTPCNUM;
        public double ADJMTR;
        public double ENDMTR;
        public int ENDPCNUM;
        public WBMOVEMENT()
        {
        }
        public WBMOVEMENT(int _ICCWBMDAT,string _ICCWBMTYPE,
            string _ICCWBMWAKZ,string _ICCWBMBS,int _ICCWBMBELEG,string _ARTICLE,string _ICCWBMBESCHICH,string _ICCWBMDPART,
            string _ICCWBMCODE,string _ICCWBMNAME,string _ICCWBMBDES,string _ICCWBMAUFTYP,string _ORDERNO,
            double _STARTMTR,int _STARTPCNUM,double _INMTR,int _INPCNUM,double _OUTMTR,int _OUTPCNUM,double _ADJMTR,double _ENDMTR,int _ENDPCNUM)
        {
            ICCWBMDAT =_ICCWBMDAT;
            ICCWBMTYPE =_ICCWBMTYPE;
            ICCWBMWAKZ =_ICCWBMWAKZ;
            ICCWBMBS =_ICCWBMBS;
            ICCWBMBELEG =_ICCWBMBELEG;
            ARTICLE =_ARTICLE;
            ICCWBMBESCHICH =_ICCWBMBESCHICH;
            ICCWBMDPART =_ICCWBMDPART;
            ICCWBMCODE =_ICCWBMCODE;
            ICCWBMNAME =_ICCWBMNAME;
            ICCWBMBDES =_ICCWBMBDES;
            ICCWBMAUFTYP =_ICCWBMAUFTYP;
            ORDERNO =_ORDERNO;
            STARTMTR =_STARTMTR;
            STARTPCNUM =_STARTPCNUM;
            INMTR =_INMTR;
            INPCNUM =_INPCNUM;
            OUTMTR =_OUTMTR;
            OUTPCNUM =_OUTPCNUM;
            ADJMTR =_ADJMTR;
            ENDMTR =_ENDMTR;
            ENDPCNUM =_ENDPCNUM;
        }
    }
    public class WGSummary
    {
        public string FACTORY;
        public string ARTICLE;
        public string WBBDPART;
        public string WBEWBESCHICH;
        public string COLORDES;
        public int PCNUM;
        public double WBEWMTR;
        public WGSummary()
        { }
        public WGSummary(string article, string wbbdpart, int pcnum, double wbewmtr)
        {
            ARTICLE = article;
            WBBDPART = wbbdpart;
            PCNUM = pcnum;
            WBEWMTR = wbewmtr;
        }
        public WGSummary(string factory,string article, string wbbdpart, int pcnum, double wbewmtr)
        {
            FACTORY = factory;
            ARTICLE = article;
            WBBDPART = wbbdpart;
            PCNUM = pcnum;
            WBEWMTR = wbewmtr;
        }
        public WGSummary(string factory, string article, string wbewbeschich, string wbbdpart, int pcnum, double wbewmtr)
        {
            FACTORY = factory;
            ARTICLE = article;
            WBEWBESCHICH = wbewbeschich;
            WBBDPART = wbbdpart;
            PCNUM = pcnum;
            WBEWMTR = wbewmtr;
        }
        public WGSummary(string factory, string article, string wbewbeschich,string colordes, string wbbdpart, int pcnum, double wbewmtr)
        {
            FACTORY = factory;
            ARTICLE = article;
            WBEWBESCHICH = wbewbeschich;
            COLORDES = colordes;
            WBBDPART = wbbdpart;
            PCNUM = pcnum;
            WBEWMTR = wbewmtr;
        }
    }
    public class BaseReport
    {
        SETEXREPORT INTEXDB = new SETEXREPORT();
        public DataTable tbExcel
        {
            get
            {
                return INTEXDB.ICC_EXPAGE1;
            }
        }
        public IntexReptServBLClient proxy;
        public OracleConnection OracleDB;
        public string strCompany = "";
        public string strExcelFile = "";
        public string Standard = "";
        public string TemplatePath = "";
        public string Root = @"R:\";
        public string destfolder = "Sales";
        public string PrintType = "JustExcel";
        public string UserID;
        public string date = "";
        public string year = "";
        public string month = "";
        public string day = "";
        ~BaseReport()
        {
            if (exAgent != null)
            {
                exAgent.Close();
                exAgent = null;
            }
        }
        public string filename = "";
        public ArrayList columns = new ArrayList();
        ExcelX.ExcelLib.ExcelAgent _exAgent;
        public ExcelX.ExcelLib.ExcelAgent exAgent
        {
            get
            {
                if (_exAgent == null)
                {
                    _exAgent = new ExcelX.ExcelLib.ExcelAgent();
                }
                return _exAgent;
            }
            set
            {
                _exAgent = value;
            }
        }    
        public DataSet dsSource;
        public Dictionary<string, object> dicSource;
        public Dictionary<string, object> dicOrigion;

        public int RowsHide = 0;
        #region Pattern
   
     
        #endregion
        public BaseReport()
        {
            
        }
        #region Tools
        public string Divide(string value, int times)
        {
            string srt = "";
            try
            {
                if (value.ToString().Trim() == "")
                    srt = "0";
                srt = (System.Convert.ToDecimal(value.ToString()) / times).ToString();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return srt;
        }
        public string GetGB2312Value(string strSource)
        {
            byte[] b;
            string filevalue = "";
            b = Encoding.GetEncoding("ISO-8859-1").GetBytes(strSource);
            filevalue = Encoding.GetEncoding("gb2312").GetString(b);
            return filevalue;
        }
        public void FillInCellbyQueue(Queue CellQueue, DataRow dwSource)
        {
            while (CellQueue.Count > 0)
            {
                string CellName = CellQueue.Dequeue() as string;
                string ColumnName = CellQueue.Dequeue() as string;
                string CellValue = GetGB2312Value(dwSource[ColumnName].ToString().Trim());
                exAgent.SetCellValue(CellName, CellValue, true);
            }
        }
        public void FillInCellbyQueue(Queue CellQueue)
        {
            while (CellQueue.Count > 0)
            {
                string CellName = CellQueue.Dequeue() as string;
                string CellValue = CellQueue.Dequeue() as string;
                exAgent.SetCellValue(CellName, CellValue, true);
            }
        }
        public string Right(string str, int num)
        {
            try
            {
                int leng = str.Length;
                str = str.Substring(leng - num, num);
            }
            catch (Exception ex)
            {
            }
            return str;
        }
        public string Left(string str, int num)
        {
            try
            {
                int leng = str.Length;
                str = str.Substring(0, num);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return str;
        }
        #endregion
        public string GetYarnDes(DataTable dtGSCOLOR, string Yarn)
        {
            string YarnDes = "";
            try
            {
                foreach (DataRow dwGSCOLOR in dtGSCOLOR.Rows)
                {
                    string GSCART = GetGB2312Value(dwGSCOLOR["GSCART"].ToString().Trim());
                    string GSCVAR = GetGB2312Value(dwGSCOLOR["GSCVAR"].ToString().Trim());
                    string GSCFARBE = GetGB2312Value(dwGSCOLOR["GSCFARBE"].ToString().Trim());
                    string GSCBEZ = GetGB2312Value(dwGSCOLOR["GSCBEZ"].ToString().Trim());
                    if (Yarn == GSCART + "/" + GSCVAR + "/" + GSCFARBE)
                    {
                        YarnDes = GSCBEZ;
                    }
                }
            }
            catch (Exception ex)
            {

                Tracer.Error(ex.StackTrace, ex);
            }
            return YarnDes;
        }
     
        public void FillInData(ArrayList columns, DataTable dtSoruce,int xStart=2,int yStart=1)
        {
            try
            {
                int x = xStart, y = yStart; 
                foreach (DataRow dataRow in dtSoruce.Rows)
                {
                    y = yStart; 
                    foreach (string columni in columns)
                    {
                        exAgent.SetCellValue(x, y, dataRow[columni].ToString());
                        y++;
                    }
                    x++;
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public virtual void SetValue(int x, int y, string value)
        {
            exAgent.SetCellValue(x, y, value);
        }
        public BaseReport(Dictionary<string, object> dicParamater)
        {
            dicOrigion = dicParamater;
        }
        public virtual void WriteExcelReport(string fileType)
        {
              
        }
        public virtual string SetFolder(string root, string sub)
        {
           return Helpers.Helper.CheckDirectory(root, sub);           
        }
    }

}
